home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / scheme / pcscheme / geneva / sources.exe / SOURCES / FONTS / GETH.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-20  |  3.1 KB  |  138 lines

  1. /*
  2. GET HERSHEY FONTS
  3. */
  4.  
  5. #include    <stdio.h>
  6. #include    <stdlib.h>
  7. #include    <string.h>
  8. #include    <ctype.h>
  9. #include    "font.h"
  10.  
  11. #define    GLYPHNUM    200
  12.  
  13. int    offset[GLYPHNUM];
  14. char    width[GLYPHNUM];
  15. unsigned data[25000];
  16.  
  17. unsigned encode( int x, int y, int line )
  18. {
  19.     union    {
  20.         struct
  21.         {
  22.             signed    xoff  : 7;
  23.             unsigned flag1 : 1;
  24.             signed    yoff  : 7;
  25.             unsigned flag2 : 1;
  26.         }    cword;
  27.         unsigned u;
  28.     }    data;
  29.     data.cword.xoff = x;
  30.     data.cword.yoff = y;
  31.     data.cword.flag1 = 1;
  32.     data.cword.flag2 = line;
  33.  
  34.     return    data.u;
  35. }
  36.  
  37. int    process( char *line, int group, char &capitol, char &descender, int &dp )
  38. {
  39.     int    first, glyph, strokes, ladj, radj, y;
  40.     char    tmp[1000];
  41.  
  42.     strcpy( tmp, line ); tmp[5] = ' ';
  43.     strcpy( tmp+6, line+5 ); tmp[9] = 0;
  44.  
  45.     sscanf( tmp, "%d %d", &glyph, &strokes );
  46.     if( glyph >= group+GLYPHNUM )
  47.         return    0;    /* done here */
  48.     glyph -= group;
  49.     line += 8;        /* skip the counts */
  50.     ladj = *line++ - 'R';
  51.     radj = *line++ - 'R';
  52.     width[glyph] = radj - ladj;
  53.     offset[glyph] = 2*dp;
  54.  
  55.     first = strokes-1;
  56.     while( --strokes > 0 )
  57.     {
  58.         if( *line == ' ')
  59.         {
  60.             data[dp++] = encode( line[2] - ladj - 'R',
  61.                 y = '[' - line[3], 0 );
  62.             line += 4;
  63.             strokes--;
  64.         } else {
  65.             data[dp++] = encode( line[0] - ladj - 'R',
  66.                 y = '[' - line[1], strokes!=first );
  67.             line += 2;
  68.         }
  69.         if( y < descender )
  70.             descender = y;
  71.         if( y > capitol )
  72.             capitol = y;
  73.     }
  74.     data[dp++] = encode( radj - ladj, 0, 0 );/* move to new pos */
  75.     data[dp++] = 0;        /* mark end */
  76.     return    1;        /* continue */
  77. }
  78.  
  79. int    main( int argc, char **argv )
  80. {
  81.     FILE    *in, *out;
  82.     char    line[1000], outname[10];
  83.     int    glyph, stroke, i, group;
  84.     HEADER    h;
  85.     struct {
  86.         char    text[60];
  87.         FHEADER    h;
  88.     }    f;
  89.  
  90.     if( (in = fopen("HERSHEY.DAT", "rt")) == NULL )
  91.         return    1;
  92.  
  93.     h.sig = SIGNATURE;
  94.     h.nchrs = 200;
  95.     h.mystery = 0;
  96.     h.first = 32;
  97.     h.cdefs = sizeof h + 3 * GLYPHNUM;
  98.     h.scan_flag = 0;
  99.     h.org_to_base = 0;
  100.     h.unused = 0;        /* still unset: org2cap, org2dec, name */
  101.  
  102.     strcpy( f.text, "PK\b\bHERSHEY fonts, (C) 1993 by Larry Bartholdi & his gang\r\n\032");
  103.     f.h.header_size = Prefix_Size;
  104.     f.h.font_major = 1, f.h.font_minor = 0;
  105.     f.h.min_major = 1, f.h.min_minor = 0;
  106.                 /* still unset: name, size */
  107.  
  108.     fgets( line, 1000, in );    /* get the machine rolling */
  109.  
  110.     for( group = 0; group < 5200; group += 200 )
  111.     {
  112.         fprintf( stderr, "Fonts %d--%d\r", group, group+GLYPHNUM-1 );
  113.  
  114.         sprintf( h.fntname, "H_%02d", group/100 );
  115.         sprintf( f.h.font_name, "H_%02d", group/100 );
  116.         sprintf( outname, "H_%02d.CHR", group/100 );
  117.         out = fopen( outname, "wb");
  118.  
  119.         for( i = 0; i < GLYPHNUM; i++ )
  120.             width[i] = offset[i] = 0;
  121.         i = 0;
  122.         data[i++] = 0;
  123.         h.org_to_cap = h.org_to_dec = 0;
  124.         while( process( line, group, h.org_to_cap, h.org_to_dec, i ) )
  125.         if( !fgets( line, 1000, in ) )
  126.             break;
  127.         f.h.font_size = sizeof h + 3*GLYPHNUM + 2*i;
  128.         fwrite( &f, Prefix_Size, 1, out );
  129.         fwrite( &h, sizeof h, 1, out );
  130.         fwrite( offset, 2 * GLYPHNUM, 1, out );
  131.         fwrite( width, GLYPHNUM, 1, out );
  132.         fwrite( data, 2*i, 1, out );
  133.         fclose( out );
  134.     }
  135.     fclose( in );
  136.     return    0;
  137. }
  138.